<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库存报表')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">货品编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="hpbh" name="hpbh" placeholder="货品编号"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">货品名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="hpmc" name="hpmc" placeholder="货品名称"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">库区名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="kqmc" name="kqmc" placeholder="库区名称"/>
                        </div>
                    </div>
                    <div class="moreSearch" style="display: none">

                    <div class="layui-inline">
                        <label class="layui-form-label">库位名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="kwmc" name="kwmc" placeholder="库位名称"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="asnbh" name="asnbh" placeholder="ASN编号"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">供应商</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="gys" name="gysmc" placeholder="供应商"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">货品批次</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="hppc" name="hppc" placeholder="货品批次"/>
                        </div>
                    </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">查询</a>
                    </div>

                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal  out-put">
                                          <i class="layui-icon">&#x1005;</i> 导出
                    </a>
                    <!-- Single button -->
                    <!--<div class="btn-group">-->
                        <!--<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"-->
                                <!--aria-haspopup="true" aria-expanded="false">-->
                            <!--多选操作 <span class="caret"></span>-->
                        <!--</button>-->
                        <!--&lt;!&ndash;<ul class="dropdown-menu">&ndash;&gt;-->
                            <!--&lt;!&ndash;<li><a id="btn_jin" href="#">批量禁用</a></li>&ndash;&gt;-->
                            <!--&lt;!&ndash;<li><a id="btn_qi" href="#">批量启用</a></li>&ndash;&gt;-->
                        <!--&lt;!&ndash;</ul>&ndash;&gt;-->
                    <!--</div>-->
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="/public/public_js::public_js"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script>


    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        });
        $("#load").on("click",function(){


            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.id;
                })
            }
            var  ids ;
           // console.log(123);
           //  var $rows = $table.bootstrapTable('getSelections');
           //  if ($rows.length == 1) {
           //      var ids = $.map($rows, function (row) {
           //          return row.id;
           //      })
           //  }

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/zxsswms/reports/getstockout", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
            xhr.send(JSON.stringify(
                object2
            ));

        })
    });





    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                /*这里激活状态那个按钮用不到，啥都不需要写，只读*/
            },
            "click #editRow": function (e, value, row, index) {//行按钮编辑  btn_stop
                editDialog(row.id, row.jhzt);
            },
            "click #btn_jin": function (e, value, row, index) {//行按钮禁用
                stopDialog(row.id);
            },
            "click #btn_qi": function (e, value, row, index) {//行按钮启用
                startDialog(row.id);
            },
            "click #load": function (e, value, row, index) {//行按钮启用
                startDialog(row.id);

                 var $rows = $table.bootstrapTable('getSelections');
                 if ($rows.length == 1) {
                     var ids = $.map($rows, function (row) {
                         return row.id;
                     })
                 }

            }


        }

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        //编辑库区
        function editDialog(id, hpzt) {

                zzpUtils.dialog({
                    title: "修改货品种类",
                    type: 2,
                    content: "/SendReceiveCategory/editCategory?id=" + id,
                    area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });

        }
        //查询字典表中的数据 订单类型
        // zzpUtils.select({
        //     elem:"#flSelect",    //dom
        //     url:"/sysdictionary/getSysdictionary/wms_owner_ordertype_fl"
        //     //路径 以"/"开头，后边正常字典路径
        // });



        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })



        /*顶部按钮导出 */
        $(".out-put").on('click', function () {
            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.id;
                })
            }
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/zxsswms/reports/getstockout", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            /*
            * 以下是将ids和对象拼接在一起
            * */
            var obj = [];
            for(var i=0;i<arr.length;i++) {
                var person = {};
                person[i] = arr[i];
                obj.push(person);
            }
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
            xhr.send(JSON.stringify(
                object2
            ));
        })//导出结束


        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/reports/getstock',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'hpbh',
                title: '货品编号'
            }, {
                field: 'hpmc',
                title: '货品名称'
            }, {
                field: 'gysmc',
                title: '供应商名称'
            }, {
                field: 'hppc',
                title: '货品批次'
            },{
                field: 'kqmc',
                title: '库区名称'
            }, {
                field: 'kwmc',
                title: '库位名称'
            },{
                field: 'sl',
                title: '总数量'
            },{
                field: 'kysl',
                title: '可用数量'
            },{
                field: 'dxjsl',
                title: '待拣货数量'
            },{
                field: 'bhsl',
                title: '待补货数量'
            },{
                field: 'djsl',
                title: '冻结数量'
            },{
                field: 'dzysl',
                title: '待转移数量'
            },{
                field: 'ydsj',
                title: '异动时间'
            },{
                field: 'rksj',
                title: '入库时间'
            },{
                field: 'asnbh',
                title: 'ASN编号'
            },
            //     {
            //     events: operateEvent,
            //     formatter: operateFormatter
            // }
            ],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            // onDblClickRow:function ( row,index) {/*双击行展示详情*/
            //     btn_cha(row.id);
            // }
        });

        /*表格右侧按钮*/
        // function operateFormatter(value, row, index) {
        //     return [
        //         /*'<a class="layui-btn layui-btn-xs" id="editRow">修改</a>',*/
        //      /*   '<a class="layui-btn layui-btn-primary layui-btn-xs" id="btn_qi"  >启用</a>',
        //
        //         '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_jin" >禁用</a>'*/
        //     ].join('')
        //
        // }

        //查询
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })
        /*新增收发类别*/
     /*   $(".add-btn").on('click', function () {
            zzpUtils.dialog({
                title: "新增收发类别",
                type: 2,
                content: "/SendReceiveCategory/add",
                area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        })*/
        /*顶部按钮编辑库区*/
        $(".edit-btn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length == 1) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })


                    zzpUtils.dialog({
                        title: "编辑货品",
                        type: 2,
                        content: "/SendReceiveCategory/editCategory?id=" + ids,
                        area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                        end: function () {//修改成功后刷新
                            zzpUtils.refreshTable("#table");
                        }
                    });
                } else {
                layer.msg("请选择一条进行编辑");
            }
        })



    });

    /*查看收发类别*/
    function cha_kuwei(id) {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.dialog({
            title: "查看收发类别",
            type: 2,
            content: "/kuqu/search_kw?id=" + id,
            area: ['60%', '60%'], //设置dialog大小，也可以不设置，
        });
    }
    /*双击查看详情*/
    // function btn_cha(id){
    //     var zzpUtils = layui.zzpUtils,
    //         $ = layui.jquery,
    //         laydate = layui.laydate;
    //     zzpUtils.dialog({
    //         title: "收发类别详情",
    //         type: 2,
    //         content: "/RepertoryReports/detailReport?id=" + id,
    //         area: ['65%', '65%'], //设置dialog大小，也可以不设置，
    //     });
    //
    // }
</script>
</html>